﻿Imports System.ComponentModel
Imports System.Text
Imports System.Threading

Namespace elevator
	Partial Public Class ElevatorSimulator
		Inherits Form
		' Constant variables 
		Private ReadOnly FIRST_FLOOR_UP_BTTN As String = "up1"
		Private ReadOnly SECOND_FLOOR_DOWN_BTTN As String = "down2"
		Private ReadOnly SECOND_FLOOR_UP_BTTN As String = "up2"
		Private ReadOnly THIRD_FLOOR_DOWN_BTTN As String = "down3"
		Private ReadOnly THIRD_FLOOR_UP_BTTN As String = "up3"
		Private ReadOnly FOURTH_FLOOR_DOWN_BTTN As String = "down4"
		Private ReadOnly FOURTH_FLOOR_UP_BTTN As String = "up4"
		Private ReadOnly FIFTH_FLOOR_DOWN_BTTN As String = "down5"

		Private ReadOnly INTERNAL_LIFT1_FL1 As String = "lift1_floor1"
		Private ReadOnly INTERNAL_LIFT1_FL2 As String = "lift1_floor2"
		Private ReadOnly INTERNAL_LIFT1_FL3 As String = "lift1_floor3"
		Private ReadOnly INTERNAL_LIFT1_FL4 As String = "lift1_floor4"
		Private ReadOnly INTERNAL_LIFT1_FL5 As String = "lift1_floor5"

		Private ReadOnly INTERNAL_LIFT2_FL1 As String = "lift2_floor1"
		Private ReadOnly INTERNAL_LIFT2_FL2 As String = "lift2_floor2"
		Private ReadOnly INTERNAL_LIFT2_FL3 As String = "lift2_floor3"
		Private ReadOnly INTERNAL_LIFT2_FL4 As String = "lift2_floor4"
		Private ReadOnly INTERNAL_LIFT2_FL5 As String = "lift2_floor5"

		Private ReadOnly INTERNAL_LIFT3_FL1 As String = "lift3_floor1"
		Private ReadOnly INTERNAL_LIFT3_FL2 As String = "lift3_floor2"
		Private ReadOnly INTERNAL_LIFT3_FL3 As String = "lift3_floor3"
		Private ReadOnly INTERNAL_LIFT3_FL4 As String = "lift3_floor4"
		Private ReadOnly INTERNAL_LIFT3_FL5 As String = "lift3_floor5"

		Private e1 As Elevator
		Private e2 As Elevator
		Private e3 As Elevator



		Public Sub New()
			InitializeComponent()

			e1 = New Elevator(panelLift1, panelLiftUI1)
			e2 = New Elevator(panelLift2, panelLiftUI2)
			e3 = New Elevator(panelLift3, panelLiftUI3)


			'e1.openDoors();
			'e2.openDoors(); 
		End Sub








		' The following controls relate to AdminUI - settting up the program 
		Private Sub bttnSetup_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnSetup.Click
			setupNumberLifts() ' show 1, 2, or 3 lifts
			setupNumberFloors() ' show 1, 2, 3, 4, or 5 floors
			setupFloorNaming() ' show either UK or US naming
			resetLifts() ' move the elevators back to floor 1
		End Sub
		Private Sub setupNumberLifts()
			If radio1lift.Checked Then
				panelShaft2.Hide()
				panelShaft3.Hide()
				panelLiftUI2.Hide()
				panelLiftUI3.Hide()
			ElseIf radio2lifts.Checked Then
				panelShaft2.Show()
				panelShaft3.Hide()
				panelLiftUI2.Show()
				panelLiftUI3.Hide()
			ElseIf radio3lifts.Checked Then
				panelShaft2.Show()
				panelShaft3.Show()
				panelLiftUI2.Show()
				panelLiftUI3.Show()
			End If
		End Sub
		Private Sub setupNumberFloors()
			If radio2floors.Checked Then
				panelFloor2.Show()
				panelFloor3.Hide()
				panelFloor4.Hide()
				panelFloor5.Hide()

				bttnLiftUI1_two.Show()
				bttnLiftUI1_three.Hide()
				bttnLiftUI1_four.Hide()
				bttnLiftUI1_five.Hide()

				bttnLiftUI2_two.Show()
				bttnLiftUI2_three.Hide()
				bttnLiftUI2_four.Hide()
				bttnLiftUI2_five.Hide()

				bttnLiftUI3_two.Show()
				bttnLiftUI3_three.Hide()
				bttnLiftUI3_four.Hide()
				bttnLiftUI3_five.Hide()

			ElseIf radio3floors.Checked Then
				panelFloor2.Show()
				panelFloor3.Show()
				panelFloor4.Hide()
				panelFloor5.Hide()

				bttnLiftUI1_two.Show()
				bttnLiftUI1_three.Show()
				bttnLiftUI1_four.Hide()
				bttnLiftUI1_five.Hide()

				bttnLiftUI2_two.Show()
				bttnLiftUI2_three.Show()
				bttnLiftUI2_four.Hide()
				bttnLiftUI2_five.Hide()

				bttnLiftUI3_two.Show()
				bttnLiftUI3_three.Show()
				bttnLiftUI3_four.Hide()
				bttnLiftUI3_five.Hide()
			ElseIf radio4floors.Checked Then
				panelFloor2.Show()
				panelFloor3.Show()
				panelFloor4.Show()
				panelFloor5.Hide()

				bttnLiftUI1_two.Show()
				bttnLiftUI1_three.Show()
				bttnLiftUI1_four.Show()
				bttnLiftUI1_five.Hide()

				bttnLiftUI2_two.Show()
				bttnLiftUI2_three.Show()
				bttnLiftUI2_four.Show()
				bttnLiftUI2_five.Hide()

				bttnLiftUI3_two.Show()
				bttnLiftUI3_three.Show()
				bttnLiftUI3_four.Show()
				bttnLiftUI3_five.Hide()
			ElseIf radio5floors.Checked Then
				panelFloor2.Show()
				panelFloor3.Show()
				panelFloor4.Show()
				panelFloor5.Show()

				bttnLiftUI1_two.Show()
				bttnLiftUI1_three.Show()
				bttnLiftUI1_four.Show()
				bttnLiftUI1_five.Show()

				bttnLiftUI2_two.Show()
				bttnLiftUI2_three.Show()
				bttnLiftUI2_four.Show()
				bttnLiftUI2_five.Show()

				bttnLiftUI3_two.Show()
				bttnLiftUI3_three.Show()
				bttnLiftUI3_four.Show()
				bttnLiftUI3_five.Show()
			End If
		End Sub
		Private Sub setupFloorNaming()
			If radioUK.Checked Then
				lblFloor1.Text = "G"
				lblFloor2.Text = "1"
				lblFloor3.Text = "2"
				lblFloor4.Text = "3"
				lblFloor5.Text = "4"

				bttnLiftUI1_one.Text = "G"
				bttnLiftUI1_two.Text = "1"
				bttnLiftUI1_three.Text = "2"
				bttnLiftUI1_four.Text = "3"
				bttnLiftUI1_five.Text = "4"

				bttnLiftUI2_one.Text = "G"
				bttnLiftUI2_two.Text = "1"
				bttnLiftUI2_three.Text = "2"
				bttnLiftUI2_four.Text = "3"
				bttnLiftUI2_five.Text = "4"

				bttnLiftUI3_one.Text = "G"
				bttnLiftUI3_two.Text = "1"
				bttnLiftUI3_three.Text = "2"
				bttnLiftUI3_four.Text = "3"
				bttnLiftUI3_five.Text = "4"
			ElseIf radioUS.Checked Then
				lblFloor1.Text = "1"
				lblFloor2.Text = "2"
				lblFloor3.Text = "3"
				lblFloor4.Text = "4"
				lblFloor5.Text = "5"

				bttnLiftUI1_one.Text = "1"
				bttnLiftUI1_two.Text = "2"
				bttnLiftUI1_three.Text = "3"
				bttnLiftUI1_four.Text = "4"
				bttnLiftUI1_five.Text = "5"

				bttnLiftUI2_one.Text = "1"
				bttnLiftUI2_two.Text = "2"
				bttnLiftUI2_three.Text = "3"
				bttnLiftUI2_four.Text = "4"
				bttnLiftUI2_five.Text = "5"

				bttnLiftUI3_one.Text = "1"
				bttnLiftUI3_two.Text = "2"
				bttnLiftUI3_three.Text = "3"
				bttnLiftUI3_four.Text = "4"
				bttnLiftUI3_five.Text = "5"
			End If
		End Sub
		Private Sub resetLifts()
			e1.reset(3, 339)
			e2.reset(3, 339)
			e3.reset(3, 339)


			turnInternalLightOff(INTERNAL_LIFT1_FL1)
			turnInternalLightOff(INTERNAL_LIFT1_FL2)
			turnInternalLightOff(INTERNAL_LIFT1_FL3)
			turnInternalLightOff(INTERNAL_LIFT1_FL4)
			turnInternalLightOff(INTERNAL_LIFT1_FL5)

			turnInternalLightOff(INTERNAL_LIFT2_FL1)
			turnInternalLightOff(INTERNAL_LIFT2_FL2)
			turnInternalLightOff(INTERNAL_LIFT2_FL3)
			turnInternalLightOff(INTERNAL_LIFT2_FL4)
			turnInternalLightOff(INTERNAL_LIFT2_FL5)

			turnInternalLightOff(INTERNAL_LIFT3_FL1)
			turnInternalLightOff(INTERNAL_LIFT3_FL2)
			turnInternalLightOff(INTERNAL_LIFT3_FL3)
			turnInternalLightOff(INTERNAL_LIFT3_FL4)
			turnInternalLightOff(INTERNAL_LIFT3_FL5)
		End Sub
		' End AdminUI controls 



		' The following controls relate to LiftUI 
		Private Sub bttnLiftUI1_one_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnLiftUI1_one.Click
			internalButtonPressed(INTERNAL_LIFT1_FL1)
		End Sub
		Private Sub bttnLiftUI1_two_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnLiftUI1_two.Click
			internalButtonPressed(INTERNAL_LIFT1_FL2)
		End Sub
		Private Sub bttnLiftUI1_three_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnLiftUI1_three.Click
			internalButtonPressed(INTERNAL_LIFT1_FL3)
		End Sub
		Private Sub bttnLiftUI1_four_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnLiftUI1_four.Click
			internalButtonPressed(INTERNAL_LIFT1_FL4)
		End Sub
		Private Sub bttnLiftUI1_five_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnLiftUI1_five.Click
			internalButtonPressed(INTERNAL_LIFT1_FL5)
		End Sub
		Private Sub bttnLiftUI2_one_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnLiftUI2_one.Click
			internalButtonPressed(INTERNAL_LIFT2_FL1)
		End Sub
		Private Sub bttnLiftUI2_two_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnLiftUI2_two.Click
			internalButtonPressed(INTERNAL_LIFT2_FL2)
		End Sub
		Private Sub bttnLiftUI2_three_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnLiftUI2_three.Click
			internalButtonPressed(INTERNAL_LIFT2_FL3)
		End Sub
		Private Sub bttnLiftUI2_four_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnLiftUI2_four.Click
			internalButtonPressed(INTERNAL_LIFT2_FL4)
		End Sub
		Private Sub bttnLiftUI2_five_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnLiftUI2_five.Click
			internalButtonPressed(INTERNAL_LIFT2_FL5)
		End Sub
		Private Sub bttnLiftUI3_one_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnLiftUI3_one.Click
			internalButtonPressed(INTERNAL_LIFT3_FL1)
		End Sub
		Private Sub bttnLiftUI3_two_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnLiftUI3_two.Click
			internalButtonPressed(INTERNAL_LIFT3_FL2)
		End Sub
		Private Sub bttnLiftUI3_three_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnLiftUI3_three.Click
			internalButtonPressed(INTERNAL_LIFT3_FL3)
		End Sub
		Private Sub bttnLiftUI3_four_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnLiftUI3_four.Click
			internalButtonPressed(INTERNAL_LIFT3_FL4)
		End Sub
		Private Sub bttnLiftUI3_five_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnLiftUI3_five.Click
			internalButtonPressed(INTERNAL_LIFT3_FL5)
		End Sub

		Private Sub internalButtonPressed(ByVal bttn As String)
			turnInternalLightOn(bttn)

			Dim command As String = ""
			If bttn.Contains("floor1") Then
				command = "floor1"
			ElseIf bttn.Contains("floor2") Then
				command = "floor2"
			ElseIf bttn.Contains("floor3") Then
				command = "floor3"
			ElseIf bttn.Contains("floor4") Then
				command = "floor4"
			ElseIf bttn.Contains("floor5") Then
				command = "floor5"
			End If


			If bttn.Contains("lift1") Then
				e1.addNewCommand(command)
			ElseIf bttn.Contains("lift2") Then
				e2.addNewCommand(command)
			ElseIf bttn.Contains("lift3") Then
				e3.addNewCommand(command)
			End If
		End Sub

		Private Sub turnInternalLightOn(ByVal bttn As String)
			If bttn.Equals(INTERNAL_LIFT1_FL1) Then
				bttnLiftUI1_one.ForeColor = Color.Yellow
			ElseIf bttn.Equals(INTERNAL_LIFT1_FL2) Then
				bttnLiftUI1_two.ForeColor = Color.Yellow
			ElseIf bttn.Equals(INTERNAL_LIFT1_FL3) Then
				bttnLiftUI1_three.ForeColor = Color.Yellow
			ElseIf bttn.Equals(INTERNAL_LIFT1_FL4) Then
				bttnLiftUI1_four.ForeColor = Color.Yellow
			ElseIf bttn.Equals(INTERNAL_LIFT1_FL5) Then
				bttnLiftUI1_five.ForeColor = Color.Yellow
			ElseIf bttn.Equals(INTERNAL_LIFT2_FL1) Then
				bttnLiftUI2_one.ForeColor = Color.Yellow
			ElseIf bttn.Equals(INTERNAL_LIFT2_FL2) Then
				bttnLiftUI2_two.ForeColor = Color.Yellow
			ElseIf bttn.Equals(INTERNAL_LIFT2_FL3) Then
				bttnLiftUI2_three.ForeColor = Color.Yellow
			ElseIf bttn.Equals(INTERNAL_LIFT2_FL4) Then
				bttnLiftUI2_four.ForeColor = Color.Yellow
			ElseIf bttn.Equals(INTERNAL_LIFT2_FL5) Then
				bttnLiftUI2_five.ForeColor = Color.Yellow
			ElseIf bttn.Equals(INTERNAL_LIFT3_FL1) Then
				bttnLiftUI3_one.ForeColor = Color.Yellow
			ElseIf bttn.Equals(INTERNAL_LIFT3_FL2) Then
				bttnLiftUI3_two.ForeColor = Color.Yellow
			ElseIf bttn.Equals(INTERNAL_LIFT3_FL3) Then
				bttnLiftUI3_three.ForeColor = Color.Yellow
			ElseIf bttn.Equals(INTERNAL_LIFT3_FL4) Then
				bttnLiftUI3_four.ForeColor = Color.Yellow
			ElseIf bttn.Equals(INTERNAL_LIFT3_FL5) Then
				bttnLiftUI3_five.ForeColor = Color.Yellow
			End If
		End Sub
		Private Sub turnInternalLightOff(ByVal bttn As String)
			If bttn.Equals(INTERNAL_LIFT1_FL1) Then
				bttnLiftUI1_one.ForeColor = Color.Black
			ElseIf bttn.Equals(INTERNAL_LIFT1_FL2) Then
				bttnLiftUI1_two.ForeColor = Color.Black
			ElseIf bttn.Equals(INTERNAL_LIFT1_FL3) Then
				bttnLiftUI1_three.ForeColor = Color.Black
			ElseIf bttn.Equals(INTERNAL_LIFT1_FL4) Then
				bttnLiftUI1_four.ForeColor = Color.Black
			ElseIf bttn.Equals(INTERNAL_LIFT1_FL5) Then
				bttnLiftUI1_five.ForeColor = Color.Black
			ElseIf bttn.Equals(INTERNAL_LIFT2_FL1) Then
				bttnLiftUI2_one.ForeColor = Color.Black
			ElseIf bttn.Equals(INTERNAL_LIFT2_FL2) Then
				bttnLiftUI2_two.ForeColor = Color.Black
			ElseIf bttn.Equals(INTERNAL_LIFT2_FL3) Then
				bttnLiftUI2_three.ForeColor = Color.Black
			ElseIf bttn.Equals(INTERNAL_LIFT2_FL4) Then
				bttnLiftUI2_four.ForeColor = Color.Black
			ElseIf bttn.Equals(INTERNAL_LIFT2_FL5) Then
				bttnLiftUI2_five.ForeColor = Color.Black
			ElseIf bttn.Equals(INTERNAL_LIFT3_FL1) Then
				bttnLiftUI3_one.ForeColor = Color.Black
			ElseIf bttn.Equals(INTERNAL_LIFT3_FL2) Then
				bttnLiftUI3_two.ForeColor = Color.Black
			ElseIf bttn.Equals(INTERNAL_LIFT3_FL3) Then
				bttnLiftUI3_three.ForeColor = Color.Black
			ElseIf bttn.Equals(INTERNAL_LIFT3_FL4) Then
				bttnLiftUI3_four.ForeColor = Color.Black
			ElseIf bttn.Equals(INTERNAL_LIFT3_FL5) Then
				bttnLiftUI3_five.ForeColor = Color.Black
			End If
		End Sub

		' The following controls relate to FloorUI 
		Private Sub bttnUp1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnUp1.Click
			buttonPressed(FIRST_FLOOR_UP_BTTN)
		End Sub ' up1
		Private Sub bttnDown2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnDown2.Click
			buttonPressed(SECOND_FLOOR_DOWN_BTTN)
		End Sub ' down2
		Private Sub bttnUp2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnUp2.Click
			buttonPressed(SECOND_FLOOR_UP_BTTN)
		End Sub ' up2
		Private Sub bttnDown3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnDown3.Click
			buttonPressed(THIRD_FLOOR_DOWN_BTTN)
		End Sub ' down3
		Private Sub bttnUp3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnUp3.Click
			buttonPressed(THIRD_FLOOR_UP_BTTN)
		End Sub ' up3
		Private Sub bttnDown4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnDown4.Click
			buttonPressed(FOURTH_FLOOR_DOWN_BTTN)
		End Sub ' down4
		Private Sub bttnUp4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnUp4.Click
			buttonPressed(FOURTH_FLOOR_UP_BTTN)
		End Sub ' up4
		Private Sub bttnDown5_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttnDown5.Click
			buttonPressed(FIFTH_FLOOR_DOWN_BTTN)
		End Sub ' down5

		Private Sub buttonPressed(ByVal bttn As String)
			turnLightOn(bttn)

			' CALCULATE RANDOM ELEVATOR HERE 
			Dim random As New Random()
			Dim max As Integer = 1
			If radio1lift.Checked Then
				max = 1
			End If
			If radio2lifts.Checked Then
				max = 2
			End If
			If radio3lifts.Checked Then
				max = 3
			End If
			Dim randomLift As Integer = random.Next(0, max)
			If randomLift = 0 Then
				e1.addNewCommand(bttn)
			ElseIf randomLift = 1 Then
				e2.addNewCommand(bttn)
			ElseIf randomLift = 2 Then
				e3.addNewCommand(bttn)
			End If
		End Sub ' Commands for when a button is pressed

		Private Sub turnLightOn(ByVal bttn As String)
			If bttn.Equals(FIRST_FLOOR_UP_BTTN) Then
				bttnUp1.Image = My.Resources.up_button_lit
			ElseIf bttn.Equals(SECOND_FLOOR_DOWN_BTTN) Then
				bttnDown2.Image = My.Resources.down_button_lit
			ElseIf bttn.Equals(SECOND_FLOOR_UP_BTTN) Then
				bttnUp2.Image = My.Resources.up_button_lit
			ElseIf bttn.Equals(THIRD_FLOOR_DOWN_BTTN) Then
				bttnDown3.Image = My.Resources.down_button_lit
			ElseIf bttn.Equals(THIRD_FLOOR_UP_BTTN) Then
				bttnUp3.Image = My.Resources.up_button_lit
			ElseIf bttn.Equals(FOURTH_FLOOR_DOWN_BTTN) Then
				bttnDown4.Image = My.Resources.down_button_lit
			ElseIf bttn.Equals(FOURTH_FLOOR_UP_BTTN) Then
				bttnUp4.Image = My.Resources.up_button_lit
			ElseIf bttn.Equals(FIFTH_FLOOR_DOWN_BTTN) Then
				bttnDown5.Image = My.Resources.down_button_lit
			End If
		End Sub
		Private Sub turnLightOff(ByVal bttn As String)
			If bttn.Equals(FIRST_FLOOR_UP_BTTN) Then
				bttnUp1.Image = My.Resources.up_button
			ElseIf bttn.Equals(SECOND_FLOOR_DOWN_BTTN) Then
				bttnDown2.Image = My.Resources.down_button
			ElseIf bttn.Equals(SECOND_FLOOR_UP_BTTN) Then
				bttnUp2.Image = My.Resources.up_button
			ElseIf bttn.Equals(THIRD_FLOOR_DOWN_BTTN) Then
				bttnDown3.Image = My.Resources.down_button
			ElseIf bttn.Equals(THIRD_FLOOR_UP_BTTN) Then
				bttnUp3.Image = My.Resources.up_button
			ElseIf bttn.Equals(FOURTH_FLOOR_DOWN_BTTN) Then
				bttnDown4.Image = My.Resources.down_button
			ElseIf bttn.Equals(FOURTH_FLOOR_UP_BTTN) Then
				bttnUp4.Image = My.Resources.up_button
			ElseIf bttn.Equals(FIFTH_FLOOR_DOWN_BTTN) Then
				bttnDown5.Image = My.Resources.down_button
			End If
		End Sub

		' Constantly checks for the position of each elevator and updates as necessary 
		Private Sub graphicUpdater_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles graphicUpdater.Tick
			e1.updateLiftPosition()
			e2.updateLiftPosition()
			e3.updateLiftPosition()
		End Sub

		' schedules the movement of each elevator 
		Private Sub e1scheduler_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles e1scheduler.Tick
			' up1 up1 up1 up1 up1 up1 up1 up1 up1 up1 up1 up1 
			If e1.getNextCommand().Equals("up1") Then
				If e1.getCurrentFloor() = 1 Then
					e1.removeCommand("up1")
					turnLightOff(FIRST_FLOOR_UP_BTTN)
					e1.setCurrentFloor(1)
					e1.openDoors()
				ElseIf e1.getCurrentFloor() = 2 OrElse e1.getCurrentFloor() = 3 OrElse e1.getCurrentFloor() = 4 OrElse e1.getCurrentFloor() = 5 Then
					If e1.getPanel().Location.Y < 339 Then
						If e1.getDoorStatus().Equals("open") Then
							e1.closeDoors()
						ElseIf e1.getDoorStatus().Equals("closed") Then
							e1.moveLift("down")
						End If
					Else
						e1.removeCommand("up1")
						turnLightOff(FIRST_FLOOR_UP_BTTN)
						e1.setCurrentFloor(1)
						e1.openDoors()
					End If
				End If
			End If



			' down2 down2 down2 down2 down2 down2 down2 down2 
			If e1.getNextCommand().Equals("down2") Then
				If e1.getCurrentFloor() = 1 Then
					If e1.getPanel().Location.Y > 252 Then
						If e1.getDoorStatus().Equals("open") Then
							e1.closeDoors()
						ElseIf e1.getDoorStatus().Equals("closed") Then
							e1.moveLift("up")
						End If
					Else
						e1.removeCommand("down2")
						turnLightOff(SECOND_FLOOR_DOWN_BTTN)
						e1.setCurrentFloor(2)
						e1.openDoors()
					End If
				ElseIf e1.getCurrentFloor() = 2 Then
					e1.removeCommand("down2")
					turnLightOff(SECOND_FLOOR_DOWN_BTTN)
					e1.setCurrentFloor(2)
					e1.openDoors()
				ElseIf e1.getCurrentFloor() = 3 OrElse e1.getCurrentFloor() = 4 OrElse e1.getCurrentFloor() = 5 Then
					If e1.getPanel().Location.Y < 252 Then
						If e1.getDoorStatus().Equals("open") Then
							e1.closeDoors()
						ElseIf e1.getDoorStatus().Equals("closed") Then
							e1.moveLift("down")
						End If
					Else
						e1.removeCommand("down2")
						turnLightOff(SECOND_FLOOR_DOWN_BTTN)
						e1.setCurrentFloor(2)
						e1.openDoors()
					End If
				End If
			End If




			' up2 up2 up2 up2 up2 up2 up2 up2 up2 up2 up2 up2 
			If e1.getNextCommand().Equals("up2") Then
				If e1.getCurrentFloor() = 1 Then
					If e1.getPanel().Location.Y > 252 Then
						If e1.getDoorStatus().Equals("open") Then
							e1.closeDoors()
						ElseIf e1.getDoorStatus().Equals("closed") Then
							e1.moveLift("up")
						End If
					Else
						e1.removeCommand("up2")
						turnLightOff(SECOND_FLOOR_UP_BTTN)
						e1.setCurrentFloor(2)
						e1.openDoors()
					End If
				ElseIf e1.getCurrentFloor() = 2 Then
					e1.removeCommand("up2")
					turnLightOff(SECOND_FLOOR_UP_BTTN)
					e1.setCurrentFloor(2)
					e1.openDoors()
				ElseIf e1.getCurrentFloor() = 3 OrElse e1.getCurrentFloor() = 4 OrElse e1.getCurrentFloor() = 5 Then
					If e1.getPanel().Location.Y < 252 Then
						If e1.getDoorStatus().Equals("open") Then
							e1.closeDoors()
						ElseIf e1.getDoorStatus().Equals("closed") Then
							e1.moveLift("down")
						End If
					Else
						e1.removeCommand("up2")
						turnLightOff(SECOND_FLOOR_UP_BTTN)
						e1.setCurrentFloor(2)
						e1.openDoors()
					End If
				End If
			End If



			' down3 down3 down3 down3 down3 down3 down3 down3 
			If e1.getNextCommand().Equals("down3") Then
				If e1.getCurrentFloor() = 1 OrElse e1.getCurrentFloor() = 2 Then
					If e1.getPanel().Location.Y > 171 Then
						If e1.getDoorStatus().Equals("open") Then
							e1.closeDoors()
						ElseIf e1.getDoorStatus().Equals("closed") Then
							e1.moveLift("up")
						End If
					Else
						e1.removeCommand("down3")
						turnLightOff(THIRD_FLOOR_DOWN_BTTN)
						e1.setCurrentFloor(3)
						e1.openDoors()
					End If
				ElseIf e1.getCurrentFloor() = 3 Then
					e1.removeCommand("down3")
					turnLightOff(THIRD_FLOOR_DOWN_BTTN)
					e1.setCurrentFloor(3)
					e1.openDoors()
				ElseIf e1.getCurrentFloor() = 4 OrElse e1.getCurrentFloor() = 5 Then
					If e1.getPanel().Location.Y < 171 Then
						If e1.getDoorStatus().Equals("open") Then
							e1.closeDoors()
						ElseIf e1.getDoorStatus().Equals("closed") Then
							e1.moveLift("down")
						End If
					Else
						e1.removeCommand("down3")
						turnLightOff(THIRD_FLOOR_DOWN_BTTN)
						e1.setCurrentFloor(3)
						e1.openDoors()
					End If
				End If
			End If



			' up3 up3 up3 up3 up3 up3 up3 up3 up3 up3 up3 up3 up3 
			If e1.getNextCommand().Equals("up3") Then
				If e1.getCurrentFloor() = 1 OrElse e1.getCurrentFloor() = 2 Then
					If e1.getPanel().Location.Y > 171 Then
						If e1.getDoorStatus().Equals("open") Then
							e1.closeDoors()
						ElseIf e1.getDoorStatus().Equals("closed") Then
							e1.moveLift("up")
						End If
					Else
						e1.removeCommand("up3")
						turnLightOff(THIRD_FLOOR_UP_BTTN)
						e1.setCurrentFloor(3)
						e1.openDoors()
					End If
				ElseIf e1.getCurrentFloor() = 3 Then
					e1.removeCommand("up3")
					turnLightOff(THIRD_FLOOR_UP_BTTN)
					e1.setCurrentFloor(3)
					e1.openDoors()
				ElseIf e1.getCurrentFloor() = 4 OrElse e1.getCurrentFloor() = 5 Then
					If e1.getPanel().Location.Y < 171 Then
						If e1.getDoorStatus().Equals("open") Then
							e1.closeDoors()
						ElseIf e1.getDoorStatus().Equals("closed") Then
							e1.moveLift("down")
						End If
					Else
						e1.removeCommand("up3")
						turnLightOff(THIRD_FLOOR_UP_BTTN)
						e1.setCurrentFloor(3)
						e1.openDoors()
					End If
				End If
			End If



			' down4 down4 down4 down4 down4 down4 down4 down4 
			If e1.getNextCommand().Equals("down4") Then
				If e1.getCurrentFloor() = 1 OrElse e1.getCurrentFloor() = 2 OrElse e1.getCurrentFloor() = 3 Then
					If e1.getPanel().Location.Y > 88 Then
						If e1.getDoorStatus().Equals("open") Then
							e1.closeDoors()
						ElseIf e1.getDoorStatus().Equals("closed") Then
							e1.moveLift("up")
						End If
					Else
						e1.removeCommand("down4")
						turnLightOff(FOURTH_FLOOR_DOWN_BTTN)
						e1.setCurrentFloor(4)
						e1.openDoors()
					End If
				ElseIf e1.getCurrentFloor() = 4 Then
					e1.removeCommand("down4")
					turnLightOff(FOURTH_FLOOR_DOWN_BTTN)
					e1.setCurrentFloor(4)
					e1.openDoors()
				ElseIf e1.getCurrentFloor() = 5 Then
					If e1.getPanel().Location.Y < 88 Then
						If e1.getDoorStatus().Equals("open") Then
							e1.closeDoors()
						ElseIf e1.getDoorStatus().Equals("closed") Then
							e1.moveLift("down")
						End If
					Else
						e1.removeCommand("down4")
						turnLightOff(FOURTH_FLOOR_DOWN_BTTN)
						e1.setCurrentFloor(4)
						e1.openDoors()
					End If
				End If
			End If





			' up4 up4 up4 up4 up4 up4 up4 up4 up4 up4 up4 up4 
			If e1.getNextCommand().Equals("up4") Then
				If e1.getCurrentFloor() = 1 OrElse e1.getCurrentFloor() = 2 OrElse e1.getCurrentFloor() = 3 Then
					If e1.getPanel().Location.Y > 88 Then
						If e1.getDoorStatus().Equals("open") Then
							e1.closeDoors()
						ElseIf e1.getDoorStatus().Equals("closed") Then
							e1.moveLift("up")
						End If
					Else
						e1.removeCommand("up4")
						turnLightOff(FOURTH_FLOOR_UP_BTTN)
						e1.setCurrentFloor(4)
						e1.openDoors()
					End If
				ElseIf e1.getCurrentFloor() = 4 Then
					e1.removeCommand("up4")
					turnLightOff(FOURTH_FLOOR_UP_BTTN)
					e1.setCurrentFloor(4)
					e1.openDoors()
				ElseIf e1.getCurrentFloor() = 5 Then
					If e1.getPanel().Location.Y < 88 Then
						If e1.getDoorStatus().Equals("open") Then
							e1.closeDoors()
						ElseIf e1.getDoorStatus().Equals("closed") Then
							e1.moveLift("down")
						End If
					Else
						e1.removeCommand("up4")
						turnLightOff(FOURTH_FLOOR_UP_BTTN)
						e1.setCurrentFloor(4)
						e1.openDoors()
					End If
				End If
			End If



			' down5 down5 down5 down5 down5 down5 down5 down5 down5 
			If e1.getNextCommand().Equals("down5") Then
				If e1.getCurrentFloor() = 1 OrElse e1.getCurrentFloor() = 2 OrElse e1.getCurrentFloor() = 3 OrElse e1.getCurrentFloor() = 4 Then
					If e1.getPanel().Location.Y > 1 Then
						If e1.getDoorStatus().Equals("open") Then
							e1.closeDoors()
						ElseIf e1.getDoorStatus().Equals("closed") Then
							e1.moveLift("up")
						End If
					Else
						e1.removeCommand("down5")
						turnLightOff(FIFTH_FLOOR_DOWN_BTTN)
						e1.setCurrentFloor(5)
						e1.openDoors()
					End If
				ElseIf e1.getCurrentFloor() = 5 Then
					e1.removeCommand("down5")
					turnLightOff(FIFTH_FLOOR_DOWN_BTTN)
					e1.setCurrentFloor(5)
					e1.openDoors()
				End If
			End If





			' floor1 floor1 floor1 floor1 floor1 floor1 floor1 floor1 floor1 
			If e1.getNextCommand().Equals("floor1") Then
				If e1.getCurrentFloor() = 1 Then
					e1.removeCommand("floor1")
					turnInternalLightOff(INTERNAL_LIFT1_FL1)
					e1.setCurrentFloor(1)
					e1.openDoors()
				ElseIf e1.getCurrentFloor() = 2 OrElse e1.getCurrentFloor() = 3 OrElse e1.getCurrentFloor() = 4 OrElse e1.getCurrentFloor() = 5 Then
					If e1.getPanel().Location.Y < 339 Then
						If e1.getDoorStatus().Equals("open") Then
							e1.closeDoors()
						ElseIf e1.getDoorStatus().Equals("closed") Then
							e1.moveLift("down")
						End If
					Else
						e1.removeCommand("floor1")
						turnInternalLightOff(INTERNAL_LIFT1_FL1)
						e1.setCurrentFloor(1)
						e1.openDoors()
					End If
				End If
			End If



			' floor2 floor2 floor2 floor2 floor2 floor2 floor2 floor2 floor2 
			If e1.getNextCommand().Equals("floor2") Then
				If e1.getCurrentFloor() = 1 Then
					If e1.getPanel().Location.Y > 252 Then
						If e1.getDoorStatus().Equals("open") Then
							e1.closeDoors()
						ElseIf e1.getDoorStatus().Equals("closed") Then
							e1.moveLift("up")
						End If
					Else
						e1.removeCommand("floor2")
						turnInternalLightOff(INTERNAL_LIFT1_FL2)
						e1.setCurrentFloor(2)
						e1.openDoors()
					End If
				ElseIf e1.getCurrentFloor() = 2 Then
					e1.removeCommand("floor2")
					turnInternalLightOff(INTERNAL_LIFT1_FL2)
					e1.setCurrentFloor(2)
					e1.openDoors()
				ElseIf e1.getCurrentFloor() = 3 OrElse e1.getCurrentFloor() = 4 OrElse e1.getCurrentFloor() = 5 Then
					If e1.getPanel().Location.Y < 252 Then
						If e1.getDoorStatus().Equals("open") Then
							e1.closeDoors()
						ElseIf e1.getDoorStatus().Equals("closed") Then
							e1.moveLift("down")
						End If
					Else
						e1.removeCommand("floor2")
						turnInternalLightOff(INTERNAL_LIFT1_FL2)
						e1.setCurrentFloor(2)
						e1.openDoors()
					End If
				End If
			End If



			' floor3 floor3 floor3 floor3 floor3 floor3 floor3 floor3 floor3 
			If e1.getNextCommand().Equals("floor3") Then
				If e1.getCurrentFloor() = 1 OrElse e1.getCurrentFloor() = 2 Then
					If e1.getPanel().Location.Y > 171 Then
						If e1.getDoorStatus().Equals("open") Then
							e1.closeDoors()
						ElseIf e1.getDoorStatus().Equals("closed") Then
							e1.moveLift("up")
						End If
					Else
						e1.removeCommand("floor3")
						turnInternalLightOff(INTERNAL_LIFT1_FL3)
						e1.setCurrentFloor(3)
						e1.openDoors()
					End If
				ElseIf e1.getCurrentFloor() = 3 Then
					e1.removeCommand("floor3")
					turnInternalLightOff(INTERNAL_LIFT1_FL3)
					e1.setCurrentFloor(3)
					e1.openDoors()
				ElseIf e1.getCurrentFloor() = 4 OrElse e1.getCurrentFloor() = 5 Then
					If e1.getPanel().Location.Y < 171 Then
						If e1.getDoorStatus().Equals("open") Then
							e1.closeDoors()
						ElseIf e1.getDoorStatus().Equals("closed") Then
							e1.moveLift("down")
						End If
					Else
						e1.removeCommand("floor3")
						turnInternalLightOff(INTERNAL_LIFT1_FL3)
						e1.setCurrentFloor(3)
						e1.openDoors()
					End If
				End If
			End If




			' floor4 floor4 floor4 floor4 floor4 floor4 floor4 floor4 floor4 floor4 
			If e1.getNextCommand().Equals("floor4") Then
				If e1.getCurrentFloor() = 1 OrElse e1.getCurrentFloor() = 2 OrElse e1.getCurrentFloor() = 3 Then
					If e1.getPanel().Location.Y > 88 Then
						If e1.getDoorStatus().Equals("open") Then
							e1.closeDoors()
						ElseIf e1.getDoorStatus().Equals("closed") Then
							e1.moveLift("up")
						End If
					Else
						e1.removeCommand("floor4")
						turnInternalLightOff(INTERNAL_LIFT1_FL4)
						e1.setCurrentFloor(4)
						e1.openDoors()
					End If
				ElseIf e1.getCurrentFloor() = 4 Then
					e1.removeCommand("floor4")
					turnInternalLightOff(INTERNAL_LIFT1_FL4)
					e1.setCurrentFloor(4)
					e1.openDoors()
				ElseIf e1.getCurrentFloor() = 5 Then
					If e1.getPanel().Location.Y < 88 Then
						If e1.getDoorStatus().Equals("open") Then
							e1.closeDoors()
						ElseIf e1.getDoorStatus().Equals("closed") Then
							e1.moveLift("down")
						End If
					Else
						e1.removeCommand("floor4")
						turnInternalLightOff(INTERNAL_LIFT1_FL4)
						e1.setCurrentFloor(4)
						e1.openDoors()
					End If
				End If
			End If


		End Sub
		Private Sub e2scheduler_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles e2scheduler.Tick
			' up1 up1 up1 up1 up1 up1 up1 up1 up1 up1 up1 up1 
			If e2.getNextCommand().Equals("up1") Then
				If e2.getCurrentFloor() = 1 Then
					e2.removeCommand("up1")
					turnLightOff(FIRST_FLOOR_UP_BTTN)
					e2.setCurrentFloor(1)
					e2.openDoors()
				ElseIf e2.getCurrentFloor() = 2 OrElse e2.getCurrentFloor() = 3 OrElse e2.getCurrentFloor() = 4 OrElse e2.getCurrentFloor() = 5 Then
					If e2.getPanel().Location.Y < 339 Then
						If e2.getDoorStatus().Equals("open") Then
							e2.closeDoors()
						ElseIf e2.getDoorStatus().Equals("closed") Then
							e2.moveLift("down")
						End If
					Else
						e2.removeCommand("up1")
						turnLightOff(FIRST_FLOOR_UP_BTTN)
						e2.setCurrentFloor(1)
						e2.openDoors()
					End If
				End If
			End If


			' down2 down2 down2 down2 down2 down2 down2 down2 
			If e2.getNextCommand().Equals("down2") Then
				If e2.getCurrentFloor() = 1 Then
					If e2.getPanel().Location.Y > 252 Then
						If e2.getDoorStatus().Equals("open") Then
							e2.closeDoors()
						ElseIf e2.getDoorStatus().Equals("closed") Then
							e2.moveLift("up")
						End If
					Else
						e2.removeCommand("down2")
						turnLightOff(SECOND_FLOOR_DOWN_BTTN)
						e2.setCurrentFloor(2)
						e2.openDoors()
					End If
				ElseIf e2.getCurrentFloor() = 2 Then
					e2.removeCommand("down2")
					turnLightOff(SECOND_FLOOR_DOWN_BTTN)
					e2.setCurrentFloor(2)
					e2.openDoors()
				ElseIf e2.getCurrentFloor() = 3 OrElse e2.getCurrentFloor() = 4 OrElse e2.getCurrentFloor() = 5 Then
					If e2.getPanel().Location.Y < 252 Then
						If e2.getDoorStatus().Equals("open") Then
							e2.closeDoors()
						ElseIf e2.getDoorStatus().Equals("closed") Then
							e2.moveLift("down")
						End If
					Else
						e2.removeCommand("down2")
						turnLightOff(SECOND_FLOOR_DOWN_BTTN)
						e2.setCurrentFloor(2)
						e2.openDoors()
					End If
				End If
			End If


			' up2 up2 up2 up2 up2 up2 up2 up2 up2 up2 up2 up2 
			If e2.getNextCommand().Equals("up2") Then
				If e2.getCurrentFloor() = 1 Then
					If e2.getPanel().Location.Y > 252 Then
						If e2.getDoorStatus().Equals("open") Then
							e2.closeDoors()
						ElseIf e2.getDoorStatus().Equals("closed") Then
							e2.moveLift("up")
						End If
					Else
						e2.removeCommand("up2")
						turnLightOff(SECOND_FLOOR_UP_BTTN)
						e2.setCurrentFloor(2)
						e2.openDoors()
					End If
				ElseIf e2.getCurrentFloor() = 2 Then
					e2.removeCommand("up2")
					turnLightOff(SECOND_FLOOR_UP_BTTN)
					e2.setCurrentFloor(2)
					e2.openDoors()
				ElseIf e2.getCurrentFloor() = 3 OrElse e2.getCurrentFloor() = 4 OrElse e2.getCurrentFloor() = 5 Then
					If e2.getPanel().Location.Y < 252 Then
						If e2.getDoorStatus().Equals("open") Then
							e2.closeDoors()
						ElseIf e2.getDoorStatus().Equals("closed") Then
							e2.moveLift("down")
						End If
					Else
						e2.removeCommand("up2")
						turnLightOff(SECOND_FLOOR_UP_BTTN)
						e2.setCurrentFloor(2)
						e2.openDoors()
					End If
				End If
			End If





			' down3 down3 down3 down3 down3 down3 down3 down3 
			If e2.getNextCommand().Equals("down3") Then
				If e2.getCurrentFloor() = 1 OrElse e2.getCurrentFloor() = 2 Then
					If e2.getPanel().Location.Y > 171 Then
						If e2.getDoorStatus().Equals("open") Then
							e2.closeDoors()
						ElseIf e2.getDoorStatus().Equals("closed") Then
							e2.moveLift("up")
						End If
					Else
						e2.removeCommand("down3")
						turnLightOff(THIRD_FLOOR_DOWN_BTTN)
						e2.setCurrentFloor(3)
						e2.openDoors()
					End If
				ElseIf e2.getCurrentFloor() = 3 Then
					e2.removeCommand("down3")
					turnLightOff(THIRD_FLOOR_DOWN_BTTN)
					e2.setCurrentFloor(3)
					e2.openDoors()
				ElseIf e2.getCurrentFloor() = 4 OrElse e2.getCurrentFloor() = 5 Then
					If e2.getPanel().Location.Y < 171 Then
						If e2.getDoorStatus().Equals("open") Then
							e2.closeDoors()
						ElseIf e2.getDoorStatus().Equals("closed") Then
							e2.moveLift("down")
						End If
					Else
						e2.removeCommand("down3")
						turnLightOff(THIRD_FLOOR_DOWN_BTTN)
						e2.setCurrentFloor(3)
						e2.openDoors()
					End If
				End If
			End If



			' up3 up3 up3 up3 up3 up3 up3 up3 up3 up3 up3 up3 up3 
			If e2.getNextCommand().Equals("up3") Then
				If e2.getCurrentFloor() = 1 OrElse e2.getCurrentFloor() = 2 Then
					If e2.getPanel().Location.Y > 171 Then
						If e2.getDoorStatus().Equals("open") Then
							e2.closeDoors()
						ElseIf e2.getDoorStatus().Equals("closed") Then
							e2.moveLift("up")
						End If
					Else
						e2.removeCommand("up3")
						turnLightOff(THIRD_FLOOR_UP_BTTN)
						e2.setCurrentFloor(3)
						e2.openDoors()
					End If
				ElseIf e3.getCurrentFloor() = 3 Then
					e2.removeCommand("up3")
					turnLightOff(THIRD_FLOOR_UP_BTTN)
					e2.setCurrentFloor(3)
					e2.openDoors()
				ElseIf e2.getCurrentFloor() = 4 OrElse e2.getCurrentFloor() = 5 Then
					If e2.getPanel().Location.Y < 171 Then
						If e2.getDoorStatus().Equals("open") Then
							e2.closeDoors()
						ElseIf e2.getDoorStatus().Equals("closed") Then
							e2.moveLift("down")
						End If
					Else
						e2.removeCommand("up3")
						turnLightOff(THIRD_FLOOR_UP_BTTN)
						e2.setCurrentFloor(3)
						e2.openDoors()
					End If
				End If
			End If


			' down4 down4 down4 down4 down4 down4 down4 down4 
			If e2.getNextCommand().Equals("down4") Then
				If e2.getCurrentFloor() = 1 OrElse e2.getCurrentFloor() = 2 OrElse e2.getCurrentFloor() = 3 Then
					If e2.getPanel().Location.Y > 88 Then
						If e2.getDoorStatus().Equals("open") Then
							e2.closeDoors()
						ElseIf e2.getDoorStatus().Equals("closed") Then
							e2.moveLift("up")
						End If
					Else
						e2.removeCommand("down4")
						turnLightOff(FOURTH_FLOOR_DOWN_BTTN)
						e2.setCurrentFloor(4)
						e2.openDoors()
					End If
				ElseIf e2.getCurrentFloor() = 4 Then
					e2.removeCommand("down4")
					turnLightOff(FOURTH_FLOOR_DOWN_BTTN)
					e2.setCurrentFloor(4)
					e2.openDoors()
				ElseIf e2.getCurrentFloor() = 5 Then
					If e2.getPanel().Location.Y < 88 Then
						If e2.getDoorStatus().Equals("open") Then
							e2.closeDoors()
						ElseIf e2.getDoorStatus().Equals("closed") Then
							e2.moveLift("down")
						End If
					Else
						e2.removeCommand("down4")
						turnLightOff(FOURTH_FLOOR_DOWN_BTTN)
						e2.setCurrentFloor(4)
						e2.openDoors()
					End If
				End If
			End If





			' up4 up4 up4 up4 up4 up4 up4 up4 up4 up4 up4 up4 
			If e2.getNextCommand().Equals("up4") Then
				If e2.getCurrentFloor() = 1 OrElse e2.getCurrentFloor() = 2 OrElse e2.getCurrentFloor() = 3 Then
					If e2.getPanel().Location.Y > 88 Then
						If e2.getDoorStatus().Equals("open") Then
							e2.closeDoors()
						ElseIf e2.getDoorStatus().Equals("closed") Then
							e2.moveLift("up")
						End If
					Else
						e2.removeCommand("up4")
						turnLightOff(FOURTH_FLOOR_UP_BTTN)
						e2.setCurrentFloor(4)
						e2.openDoors()
					End If
				ElseIf e2.getCurrentFloor() = 4 Then
					e2.removeCommand("up4")
					turnLightOff(FOURTH_FLOOR_UP_BTTN)
					e2.setCurrentFloor(4)
					e2.openDoors()
				ElseIf e2.getCurrentFloor() = 5 Then
					If e2.getPanel().Location.Y < 88 Then
						If e2.getDoorStatus().Equals("open") Then
							e2.closeDoors()
						ElseIf e2.getDoorStatus().Equals("closed") Then
							e2.moveLift("down")
						End If
					Else
						e2.removeCommand("up4")
						turnLightOff(FOURTH_FLOOR_UP_BTTN)
						e2.setCurrentFloor(4)
						e2.openDoors()
					End If
				End If
			End If


			' down5 down5 down5 down5 down5 down5 down5 down5 down5 
			If e2.getNextCommand().Equals("down5") Then
				If e2.getCurrentFloor() = 1 OrElse e2.getCurrentFloor() = 2 OrElse e2.getCurrentFloor() = 3 OrElse e2.getCurrentFloor() = 4 Then
					If e2.getPanel().Location.Y > 1 Then
						If e2.getDoorStatus().Equals("open") Then
							e2.closeDoors()
						ElseIf e2.getDoorStatus().Equals("closed") Then
							e2.moveLift("up")
						End If
					Else
						e2.removeCommand("down5")
						turnLightOff(FIFTH_FLOOR_DOWN_BTTN)
						e2.setCurrentFloor(5)
						e2.openDoors()
					End If
				ElseIf e2.getCurrentFloor() = 5 Then
					e2.removeCommand("down5")
					turnLightOff(FIFTH_FLOOR_DOWN_BTTN)
					e2.setCurrentFloor(5)
					e2.openDoors()
				End If
			End If




			' floor1 floor1 floor1 floor1 floor1 floor1 floor1 floor1 floor1 
			If e2.getNextCommand().Equals("floor1") Then
				If e2.getCurrentFloor() = 1 Then
					e2.removeCommand("floor1")
					turnInternalLightOff(INTERNAL_LIFT2_FL1)
					e2.setCurrentFloor(1)
					e2.openDoors()
				ElseIf e2.getCurrentFloor() = 2 OrElse e2.getCurrentFloor() = 3 OrElse e2.getCurrentFloor() = 4 OrElse e2.getCurrentFloor() = 5 Then
					If e2.getPanel().Location.Y < 339 Then
						If e2.getDoorStatus().Equals("open") Then
							e2.closeDoors()
						ElseIf e2.getDoorStatus().Equals("closed") Then
							e2.moveLift("down")
						End If
					Else
						e2.removeCommand("floor1")
						turnInternalLightOff(INTERNAL_LIFT2_FL1)
						e2.setCurrentFloor(1)
						e2.openDoors()
					End If
				End If
			End If




			' floor2 floor2 floor2 floor2 floor2 floor2 floor2 floor2 floor2 
			If e2.getNextCommand().Equals("floor2") Then
				If e2.getCurrentFloor() = 1 Then
					If e2.getPanel().Location.Y > 252 Then
						If e2.getDoorStatus().Equals("open") Then
							e2.closeDoors()
						ElseIf e2.getDoorStatus().Equals("closed") Then
							e2.moveLift("up")
						End If
					Else
						e2.removeCommand("floor2")
						turnInternalLightOff(INTERNAL_LIFT2_FL2)
						e2.setCurrentFloor(2)
						e2.openDoors()
					End If
				ElseIf e2.getCurrentFloor() = 2 Then
					e2.removeCommand("floor2")
					turnInternalLightOff(INTERNAL_LIFT2_FL2)
					e2.setCurrentFloor(2)
					e2.openDoors()
				ElseIf e2.getCurrentFloor() = 3 OrElse e2.getCurrentFloor() = 4 OrElse e2.getCurrentFloor() = 5 Then
					If e2.getPanel().Location.Y < 252 Then
						If e2.getDoorStatus().Equals("open") Then
							e2.closeDoors()
						ElseIf e2.getDoorStatus().Equals("closed") Then
							e2.moveLift("down")
						End If
					Else
						e2.removeCommand("floor2")
						turnInternalLightOff(INTERNAL_LIFT2_FL2)
						e2.setCurrentFloor(2)
						e2.openDoors()
					End If
				End If
			End If



			' floor3 floor3 floor3 floor3 floor3 floor3 floor3 floor3 floor3 
			If e2.getNextCommand().Equals("floor3") Then
				If e2.getCurrentFloor() = 1 OrElse e2.getCurrentFloor() = 2 Then
					If e2.getPanel().Location.Y > 171 Then
						If e2.getDoorStatus().Equals("open") Then
							e2.closeDoors()
						ElseIf e2.getDoorStatus().Equals("closed") Then
							e2.moveLift("up")
						End If
					Else
						e2.removeCommand("floor3")
						turnInternalLightOff(INTERNAL_LIFT2_FL3)
						e2.setCurrentFloor(3)
						e2.openDoors()
					End If
				ElseIf e2.getCurrentFloor() = 3 Then
					e2.removeCommand("floor3")
					turnInternalLightOff(INTERNAL_LIFT2_FL3)
					e2.setCurrentFloor(3)
					e2.openDoors()
				ElseIf e2.getCurrentFloor() = 4 OrElse e2.getCurrentFloor() = 5 Then
					If e2.getPanel().Location.Y < 171 Then
						If e2.getDoorStatus().Equals("open") Then
							e2.closeDoors()
						ElseIf e2.getDoorStatus().Equals("closed") Then
							e2.moveLift("down")
						End If
					Else
						e2.removeCommand("floor3")
						turnInternalLightOff(INTERNAL_LIFT2_FL3)
						e2.setCurrentFloor(3)
						e2.openDoors()
					End If
				End If
			End If




			' floor4 floor4 floor4 floor4 floor4 floor4 floor4 floor4 floor4 floor4 
			If e2.getNextCommand().Equals("floor4") Then
				If e2.getCurrentFloor() = 1 OrElse e2.getCurrentFloor() = 2 OrElse e2.getCurrentFloor() = 3 Then
					If e2.getPanel().Location.Y > 88 Then
						If e2.getDoorStatus().Equals("open") Then
							e2.closeDoors()
						ElseIf e2.getDoorStatus().Equals("closed") Then
							e2.moveLift("up")
						End If
					Else
						e2.removeCommand("floor4")
						turnInternalLightOff(INTERNAL_LIFT2_FL4)
						e2.setCurrentFloor(4)
						e2.openDoors()
					End If
				ElseIf e2.getCurrentFloor() = 4 Then
					e2.removeCommand("floor4")
					turnInternalLightOff(INTERNAL_LIFT2_FL4)
					e2.setCurrentFloor(4)
					e2.openDoors()
				ElseIf e2.getCurrentFloor() = 5 Then
					If e2.getPanel().Location.Y < 88 Then
						If e2.getDoorStatus().Equals("open") Then
							e2.closeDoors()
						ElseIf e2.getDoorStatus().Equals("closed") Then
							e2.moveLift("down")
						End If
					Else
						e2.removeCommand("floor4")
						turnInternalLightOff(INTERNAL_LIFT2_FL4)
						e2.setCurrentFloor(4)
						e2.openDoors()
					End If
				End If
			End If


		End Sub
		Private Sub e3scheduler_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles e3scheduler.Tick
			' up1 up1 up1 up1 up1 up1 up1 up1 up1 up1 up1 up1 
			If e3.getNextCommand().Equals("up1") Then
				If e3.getCurrentFloor() = 1 Then
					e3.removeCommand("up1")
					turnLightOff(FIRST_FLOOR_UP_BTTN)
					e3.setCurrentFloor(1)
					e3.openDoors()
				ElseIf e3.getCurrentFloor() = 2 OrElse e3.getCurrentFloor() = 3 OrElse e3.getCurrentFloor() = 4 OrElse e3.getCurrentFloor() = 5 Then
					If e3.getPanel().Location.Y < 339 Then
						If e3.getDoorStatus().Equals("open") Then
							e3.closeDoors()
						ElseIf e3.getDoorStatus().Equals("closed") Then
							e3.moveLift("down")
						End If
					Else
						e3.removeCommand("up1")
						turnLightOff(FIRST_FLOOR_UP_BTTN)
						e3.setCurrentFloor(1)
						e3.openDoors()
					End If
				End If
			End If



			' down2 down2 down2 down2 down2 down2 down2 down2 
			If e3.getNextCommand().Equals("down2") Then
				If e3.getCurrentFloor() = 1 Then
					If e3.getPanel().Location.Y > 252 Then
						If e3.getDoorStatus().Equals("open") Then
							e3.closeDoors()
						ElseIf e3.getDoorStatus().Equals("closed") Then
							e3.moveLift("up")
						End If
					Else
						e3.removeCommand("down2")
						turnLightOff(SECOND_FLOOR_DOWN_BTTN)
						e3.setCurrentFloor(2)
						e3.openDoors()
					End If
				ElseIf e3.getCurrentFloor() = 2 Then
					e3.removeCommand("down2")
					turnLightOff(SECOND_FLOOR_DOWN_BTTN)
					e3.setCurrentFloor(2)
					e3.openDoors()
				ElseIf e3.getCurrentFloor() = 3 OrElse e3.getCurrentFloor() = 4 OrElse e3.getCurrentFloor() = 5 Then
					If e3.getPanel().Location.Y < 252 Then
						If e3.getDoorStatus().Equals("open") Then
							e3.closeDoors()
						ElseIf e3.getDoorStatus().Equals("closed") Then
							e3.moveLift("down")
						End If
					Else
						e3.removeCommand("down2")
						turnLightOff(SECOND_FLOOR_DOWN_BTTN)
						e3.setCurrentFloor(2)
						e3.openDoors()
					End If
				End If
			End If



			' up2 up2 up2 up2 up2 up2 up2 up2 up2 up2 up2 up2 
			If e3.getNextCommand().Equals("up2") Then
				If e3.getCurrentFloor() = 1 Then
					If e3.getPanel().Location.Y > 252 Then
						If e3.getDoorStatus().Equals("open") Then
							e3.closeDoors()
						ElseIf e3.getDoorStatus().Equals("closed") Then
							e3.moveLift("up")
						End If
					Else
						e3.removeCommand("up2")
						turnLightOff(SECOND_FLOOR_UP_BTTN)
						e3.setCurrentFloor(2)
						e3.openDoors()
					End If
				ElseIf e3.getCurrentFloor() = 2 Then
					e3.removeCommand("up2")
					turnLightOff(SECOND_FLOOR_UP_BTTN)
					e3.setCurrentFloor(2)
					e3.openDoors()
				ElseIf e3.getCurrentFloor() = 3 OrElse e3.getCurrentFloor() = 4 OrElse e3.getCurrentFloor() = 5 Then
					If e3.getPanel().Location.Y < 252 Then
						If e3.getDoorStatus().Equals("open") Then
							e3.closeDoors()
						ElseIf e3.getDoorStatus().Equals("closed") Then
							e3.moveLift("down")
						End If
					Else
						e3.removeCommand("up2")
						turnLightOff(SECOND_FLOOR_UP_BTTN)
						e3.setCurrentFloor(2)
						e3.openDoors()
					End If
				End If
			End If





			' down3 down3 down3 down3 down3 down3 down3 down3 
			If e3.getNextCommand().Equals("down3") Then
				If e3.getCurrentFloor() = 1 OrElse e3.getCurrentFloor() = 2 Then
					If e3.getPanel().Location.Y > 171 Then
						If e3.getDoorStatus().Equals("open") Then
							e3.closeDoors()
						ElseIf e3.getDoorStatus().Equals("closed") Then
							e3.moveLift("up")
						End If
					Else
						e3.removeCommand("down3")
						turnLightOff(THIRD_FLOOR_DOWN_BTTN)
						e3.setCurrentFloor(3)
						e3.openDoors()
					End If
				ElseIf e3.getCurrentFloor() = 3 Then
					e3.removeCommand("down3")
					turnLightOff(THIRD_FLOOR_DOWN_BTTN)
					e3.setCurrentFloor(3)
					e3.openDoors()
				ElseIf e3.getCurrentFloor() = 4 OrElse e3.getCurrentFloor() = 5 Then
					If e3.getPanel().Location.Y < 171 Then
						If e3.getDoorStatus().Equals("open") Then
							e3.closeDoors()
						ElseIf e3.getDoorStatus().Equals("closed") Then
							e3.moveLift("down")
						End If
					Else
						e3.removeCommand("down3")
						turnLightOff(THIRD_FLOOR_DOWN_BTTN)
						e3.setCurrentFloor(3)
						e3.openDoors()
					End If
				End If
			End If





			' up3 up3 up3 up3 up3 up3 up3 up3 up3 up3 up3 up3 up3 
			If e3.getNextCommand().Equals("up3") Then
				If e3.getCurrentFloor() = 1 OrElse e3.getCurrentFloor() = 2 Then
					If e3.getPanel().Location.Y > 171 Then
						If e3.getDoorStatus().Equals("open") Then
							e3.closeDoors()
						ElseIf e3.getDoorStatus().Equals("closed") Then
							e3.moveLift("up")
						End If
					Else
						e3.removeCommand("up3")
						turnLightOff(THIRD_FLOOR_UP_BTTN)
						e3.setCurrentFloor(3)
						e3.openDoors()
					End If
				ElseIf e3.getCurrentFloor() = 3 Then
					e3.removeCommand("up3")
					turnLightOff(THIRD_FLOOR_UP_BTTN)
					e3.setCurrentFloor(3)
					e3.openDoors()
				ElseIf e3.getCurrentFloor() = 4 OrElse e3.getCurrentFloor() = 5 Then
					If e3.getPanel().Location.Y < 171 Then
						If e3.getDoorStatus().Equals("open") Then
							e3.closeDoors()
						ElseIf e3.getDoorStatus().Equals("closed") Then
							e3.moveLift("down")
						End If
					Else
						e3.removeCommand("up3")
						turnLightOff(THIRD_FLOOR_UP_BTTN)
						e3.setCurrentFloor(3)
						e3.openDoors()
					End If
				End If
			End If




			' down4 down4 down4 down4 down4 down4 down4 down4 
			If e3.getNextCommand().Equals("down4") Then
				If e3.getCurrentFloor() = 1 OrElse e3.getCurrentFloor() = 2 OrElse e3.getCurrentFloor() = 3 Then
					If e3.getPanel().Location.Y > 88 Then
						If e3.getDoorStatus().Equals("open") Then
							e3.closeDoors()
						ElseIf e3.getDoorStatus().Equals("closed") Then
							e3.moveLift("up")
						End If
					Else
						e3.removeCommand("down4")
						turnLightOff(FOURTH_FLOOR_DOWN_BTTN)
						e3.setCurrentFloor(4)
						e3.openDoors()
					End If
				ElseIf e3.getCurrentFloor() = 4 Then
					e3.removeCommand("down4")
					turnLightOff(FOURTH_FLOOR_DOWN_BTTN)
					e3.setCurrentFloor(4)
					e3.openDoors()
				ElseIf e3.getCurrentFloor() = 5 Then
					If e3.getPanel().Location.Y < 88 Then
						If e3.getDoorStatus().Equals("open") Then
							e3.closeDoors()
						ElseIf e3.getDoorStatus().Equals("closed") Then
							e3.moveLift("down")
						End If
					Else
						e3.removeCommand("down4")
						turnLightOff(FOURTH_FLOOR_DOWN_BTTN)
						e3.setCurrentFloor(4)
						e3.openDoors()
					End If
				End If
			End If




			' up4 up4 up4 up4 up4 up4 up4 up4 up4 up4 up4 up4 
			If e3.getNextCommand().Equals("up4") Then
				If e3.getCurrentFloor() = 1 OrElse e3.getCurrentFloor() = 2 OrElse e3.getCurrentFloor() = 3 Then
					If e3.getPanel().Location.Y > 88 Then
						If e3.getDoorStatus().Equals("open") Then
							e3.closeDoors()
						ElseIf e3.getDoorStatus().Equals("closed") Then
							e3.moveLift("up")
						End If
					Else
						e3.removeCommand("up4")
						turnLightOff(FOURTH_FLOOR_UP_BTTN)
						e3.setCurrentFloor(4)
						e3.openDoors()
					End If
				ElseIf e3.getCurrentFloor() = 4 Then
					e3.removeCommand("up4")
					turnLightOff(FOURTH_FLOOR_UP_BTTN)
					e3.setCurrentFloor(4)
					e3.openDoors()
				ElseIf e3.getCurrentFloor() = 5 Then
					If e3.getPanel().Location.Y < 88 Then
						If e3.getDoorStatus().Equals("open") Then
							e3.closeDoors()
						ElseIf e3.getDoorStatus().Equals("closed") Then
							e3.moveLift("down")
						End If
					Else
						e3.removeCommand("up4")
						turnLightOff(FOURTH_FLOOR_UP_BTTN)
						e3.setCurrentFloor(4)
						e3.openDoors()
					End If
				End If
			End If




			' down5 down5 down5 down5 down5 down5 down5 down5 down5 
			If e3.getNextCommand().Equals("down5") Then
				If e3.getCurrentFloor() = 1 OrElse e3.getCurrentFloor() = 2 OrElse e3.getCurrentFloor() = 3 OrElse e3.getCurrentFloor() = 4 Then
					If e3.getPanel().Location.Y > 1 Then
						If e3.getDoorStatus().Equals("open") Then
							e3.closeDoors()
						ElseIf e3.getDoorStatus().Equals("closed") Then
							e3.moveLift("up")
						End If
					Else
						e3.removeCommand("down5")
						turnLightOff(FIFTH_FLOOR_DOWN_BTTN)
						e3.setCurrentFloor(5)
						e3.openDoors()
					End If
				ElseIf e3.getCurrentFloor() = 5 Then
					e3.removeCommand("down5")
					turnLightOff(FIFTH_FLOOR_DOWN_BTTN)
					e3.setCurrentFloor(5)
					e3.openDoors()
				End If
			End If




			' floor1 floor1 floor1 floor1 floor1 floor1 floor1 floor1 floor1 
			If e3.getNextCommand().Equals("floor1") Then
				If e3.getCurrentFloor() = 1 Then
					e3.removeCommand("floor1")
					turnInternalLightOff(INTERNAL_LIFT3_FL1)
					e3.setCurrentFloor(1)
					e3.openDoors()
				ElseIf e3.getCurrentFloor() = 2 OrElse e3.getCurrentFloor() = 3 OrElse e3.getCurrentFloor() = 4 OrElse e3.getCurrentFloor() = 5 Then
					If e3.getPanel().Location.Y < 339 Then
						If e3.getDoorStatus().Equals("open") Then
							e3.closeDoors()
						ElseIf e3.getDoorStatus().Equals("closed") Then
							e3.moveLift("down")
						End If
					Else
						e3.removeCommand("floor1")
						turnInternalLightOff(INTERNAL_LIFT3_FL1)
						e3.setCurrentFloor(1)
						e3.openDoors()
					End If
				End If
			End If




			' floor2 floor2 floor2 floor2 floor2 floor2 floor2 floor2 floor2 
			If e3.getNextCommand().Equals("floor2") Then
				If e3.getCurrentFloor() = 1 Then
					If e3.getPanel().Location.Y > 252 Then
						If e3.getDoorStatus().Equals("open") Then
							e3.closeDoors()
						ElseIf e3.getDoorStatus().Equals("closed") Then
							e3.moveLift("up")
						End If
					Else
						e3.removeCommand("floor2")
						turnInternalLightOff(INTERNAL_LIFT3_FL2)
						e3.setCurrentFloor(2)
						e3.openDoors()
					End If
				ElseIf e3.getCurrentFloor() = 2 Then
					e3.removeCommand("floor2")
					turnInternalLightOff(INTERNAL_LIFT3_FL2)
					e3.setCurrentFloor(2)
					e3.openDoors()
				ElseIf e3.getCurrentFloor() = 3 OrElse e3.getCurrentFloor() = 4 OrElse e3.getCurrentFloor() = 5 Then
					If e3.getPanel().Location.Y < 252 Then
						If e3.getDoorStatus().Equals("open") Then
							e3.closeDoors()
						ElseIf e3.getDoorStatus().Equals("closed") Then
							e3.moveLift("down")
						End If
					Else
						e3.removeCommand("floor2")
						turnInternalLightOff(INTERNAL_LIFT3_FL2)
						e3.setCurrentFloor(2)
						e3.openDoors()
					End If
				End If
			End If



			' floor3 floor3 floor3 floor3 floor3 floor3 floor3 floor3 floor3 
			If e3.getNextCommand().Equals("floor3") Then
				If e3.getCurrentFloor() = 1 OrElse e3.getCurrentFloor() = 2 Then
					If e3.getPanel().Location.Y > 171 Then
						If e3.getDoorStatus().Equals("open") Then
							e3.closeDoors()
						ElseIf e3.getDoorStatus().Equals("closed") Then
							e3.moveLift("up")
						End If
					Else
						e3.removeCommand("floor3")
						turnInternalLightOff(INTERNAL_LIFT3_FL3)
						e3.setCurrentFloor(3)
						e3.openDoors()
					End If
				ElseIf e3.getCurrentFloor() = 3 Then
					e3.removeCommand("floor3")
					turnInternalLightOff(INTERNAL_LIFT3_FL3)
					e3.setCurrentFloor(3)
					e3.openDoors()
				ElseIf e3.getCurrentFloor() = 4 OrElse e3.getCurrentFloor() = 5 Then
					If e3.getPanel().Location.Y < 171 Then
						If e3.getDoorStatus().Equals("open") Then
							e3.closeDoors()
						ElseIf e3.getDoorStatus().Equals("closed") Then
							e3.moveLift("down")
						End If
					Else
						e3.removeCommand("floor3")
						turnInternalLightOff(INTERNAL_LIFT3_FL3)
						e3.setCurrentFloor(3)
						e3.openDoors()
					End If
				End If
			End If



			' floor4 floor4 floor4 floor4 floor4 floor4 floor4 floor4 floor4 floor4 
			If e3.getNextCommand().Equals("floor4") Then
				If e3.getCurrentFloor() = 1 OrElse e3.getCurrentFloor() = 2 OrElse e3.getCurrentFloor() = 3 Then
					If e3.getPanel().Location.Y > 88 Then
						If e3.getDoorStatus().Equals("open") Then
							e3.closeDoors()
						ElseIf e3.getDoorStatus().Equals("closed") Then
							e3.moveLift("up")
						End If
					Else
						e3.removeCommand("floor4")
						turnInternalLightOff(INTERNAL_LIFT3_FL4)
						e3.setCurrentFloor(4)
						e3.openDoors()
					End If
				ElseIf e3.getCurrentFloor() = 4 Then
					e3.removeCommand("floor4")
					turnInternalLightOff(INTERNAL_LIFT3_FL4)
					e3.setCurrentFloor(4)
					e3.openDoors()
				ElseIf e3.getCurrentFloor() = 5 Then
					If e3.getPanel().Location.Y < 88 Then
						If e3.getDoorStatus().Equals("open") Then
							e3.closeDoors()
						ElseIf e3.getDoorStatus().Equals("closed") Then
							e3.moveLift("down")
						End If
					Else
						e3.removeCommand("floor4")
						turnInternalLightOff(INTERNAL_LIFT3_FL4)
						e3.setCurrentFloor(4)
						e3.openDoors()
					End If
				End If
			End If


		End Sub
	End Class
End Namespace
